#!/usr/bin/perl
#modify.cgi

require './shareman-lib.pl';
&ReadParse();
&error_setup($text{'error_mesg'});

$hour=$in{'hour'};
$day=$in{'day'};
$month=$in{'month'};

$action = 1;
if($action){
    $line="0 ".$hour." ".$day." ".$month." * /etc/rc.d/filter.pl\n";
    open(FH, "/sysvol/etc/cronfile");
    @cron_change=<FH>;
    $cron_num_change=@cron_change;
    close(FH);
    unlink("/sysvol/etc/cronfile_tmp");
    open(FHB, ">>/sysvol/etc/cronfile_tmp");
    if($cron_num_change == 0){
	 print FHB $line;
    }
    for($i=0; $i<$cron_num_change; $i++){
         if($cron_change[$i] =~ /filter/){
             print FHB $line; 
         }else{
             print FHB $cron_change[$i];
         }
    }
    close(FHB);
    #&error($cron_num_change);
    unlink("/sysvol/etc/cronfile");
    rename("/sysvol/etc/cronfile_tmp","/sysvol/etc/cronfile");
}
system('crontab /sysvol/etc/cronfile');
system('/etc/init.d/crond restart');
&redirect("index.cgi");
